<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>订单状态编辑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
</head>
<body>

<div class="layui-form" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">
    <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label">订单编号：</label>-->
        <!--<label class="layui-form-label layui-gray" style="text-align:left; padding-left:0px;" id="orderNo"></label>-->
    <!--</div>-->
    <!--<div class="layui-form-item">-->
    <!--<label class="layui-form-label">剩余金额：</label>-->
    <!--<label class="layui-form-label layui-gray" style="text-align:left; padding-left:0px;">500</label>-->
    <!--</div>-->
    <!--<div class="layui-form-item kd1">-->
    <!--<label class="layui-form-label">搜索商品：</label>-->
    <!--<div class="layui-input-inline" style="width:320px;">-->
    <!--<input type="text" name="userName" id="userName" autocomplete="off" class="layui-input" value="商品名称">-->
    <!--</div>-->
    <!--</div>-->
    <div class="layui-form-item">
        <!--<label class="layui-form-label">选择商品：</label>-->
        <!--<div class="layui-input-inline" style="width:150px;">-->
        <!--<select name="orderStatus" id="orderStatus"  lay-verify="required" lay-filter="select1">-->
        <!--<option selected="selected" value="703">商品名称2（1000）</option>-->
        <!--<option value="701">商品名称4（1000）</option>-->
        <!--</select>-->
        <!--</div>-->

        <!--<div class="layui-input-inline" style="width:50px;">-->
        <!--<input type="text" name="userName" id="userName" autocomplete="off" class="layui-input" value="1">-->
        <!--</div>-->
        <!--<div class="layui-input-inline" style="width:100px;">-->
        <!--<button class="layui-btn layuiadmin-btn-admin" data-type="add" onclick="Add();" >添加</button>-->
        <!--</div>-->
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">选择商品：</label>
        <!--<label class="layui-form-label layui-gray" id="goodsinfo" style="text-align:left; padding-left:0px;width:300px;">-->
<input type="button" value="打开" onclick="opengoods();">
        <!--</label>-->
        <!--<div id="goodsinfo"></div>-->

    </div>
    <div class="layui-form-item kd1">
        <label class="layui-form-label">确认商品：</label>
        <div class="layui-input-inline" id="goodsinfo" style="width:320px;">
            <!--<label id="goodsinfo1"></label>-->
            <!--<input type="text" name="userName" id="ss" autocomplete="off" class="layui-input" value="">-->
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">物流类型：</label>
        <div class="layui-input-inline">
            <select name="logType" id="logType"  lay-verify="required" lay-filter="logType">
                <option selected="selected" value="1">快递</option>
                <option value="2">自提</option>
            </select>
        </div>
    </div>
    <!--<div class="layui-form-item kd1" style="background-color:#333;">-->
    <!--<label class="layui-form-label">自提店名：</label>-->
    <!--<div class="layui-input-inline" style="width:320px;">-->
    <!--<input type="text" name="userName" id="userName" autocomplete="off" class="layui-input" value="自提店名">-->
    <!--</div>-->
    <!--</div>-->
    <div class="layui-form-item kd1">
        <label class="layui-form-label">收货姓名：</label>
        <div class="layui-input-inline" style="width:320px;">
            <input type="text" name="userName" id="logName" autocomplete="off" class="layui-input" value="">
        </div>
    </div>
    <div class="layui-form-item kd1">
        <label class="layui-form-label">收货电话：</label>
        <div class="layui-input-inline" style="width:320px;">
            <input type="text" name="phone" id="phone" autocomplete="off" class="layui-input" value="">
        </div>
    </div>
    <div class="layui-form-item kd1">
        <label class="layui-form-label">收货地址：</label>
        <div class="layui-input-inline" style="width:100px;">
            <select name="quiz0" id="quiz0" lay-filter="quiz0">
                <!--<option value="-1">请选择</option>-->
            </select>
        </div>
        <div class="layui-input-inline" style="width:100px;">
            <select name="quiz1" id="quiz1" lay-filter="quiz1">
                <!--<option value="-1">请选择</option>-->
            </select>
        </div>
        <div class="layui-input-inline" style="width:100px;">
            <select name="quiz2" id="quiz2" lay-filter="quiz2">
                <!--<option value="-1">请选择</option>-->
            </select>
        </div>
    </div>
    <div class="layui-form-item kd1">
        <label class="layui-form-label">详细地址：</label>
        <div class="layui-input-inline" style="width:320px;">
            <input type="text" name="detail_addr" id="detailAddr" autocomplete="off" class="layui-input" value="">
        </div>
    </div>
    <div class="layui-form-item kd1">
        <label class="layui-form-label">提交人：</label>
        <div class="layui-input-inline" style="width:320px;">
            <input type="text" name="detail_addr" id="submitter" autocomplete="off" class="layui-input" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">订单备注：</label>
        <div class="layui-input-inline" style="width:320px;">
            <textarea name="note" placeholder="请输入内容" id="remark" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <input type="button" style="margin-left: 25px;" onclick="sure(this);" lay-submit lay-filter="LAY-user-front-submit" id="LAY-user-back-submit" value="确认">
    </div>
</div>
<script src="/layui/jquery.min.js"></script>
<script src="/layui/layui.all.js"></script>
<script>
    layui.config({
        base: '/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function(){
        var $ = layui.$
            ,form = layui.form ;
    })
    var sInfo="";
    function opengoods() {
        //弹出即全屏
        var index2 = layer.open({
            type: 2,
            title: " ",
            btn: ['确定', '取消'],
            content: '/order/order/createGoodsList.html',
            area: ['1000px', '750px']
           ,maxmin: true
            , yes: function (index, layero) {
                var specinfo=window[layero.find('iframe')[0]['name']].specinfo;
                var info =JSON.parse(JSON.stringify(specinfo));//specinfo.parseJSON();
                sInfo=JSON.stringify(specinfo);
                var  params = [];
                for(var p in info){
                    var obj = {};
                    obj['id'] = info[p].id;
                    obj['pCount'] = info[p].pCount;
                    obj['goodsId'] = info[p].goodsId;

                    params.push(obj);
                }
                sInfo=JSON.stringify(params);
                var loggoodsinfo="";
                $.each(info, function(i, item){

    loggoodsinfo +="<label data-p='"+item.goodsId+"' data-g='"+item.id+"' data-c='"+item.pCount+"'  type='checkbox' " +
             "name='goodsinfo' lay-filter='goodsinfo' lay-skin='primary' checked >"+item.name+" 数量:"+item.pCount+" 价格:"+item.price+"</label><br>";
                });
                $("#goodsinfo").append(loggoodsinfo);

                // specInfo=$.trim(parent.specinfo);
                // alert(specInfo);
                // //当点击‘确定’按钮的时候，获取弹出层返回的值
                // var res = window["layui-layer-iframe" + index].callbackdata();
                // //打印返回的值，看是否有我们想返回的值。
                // console.log(res);
                // //最后关闭弹出层
                  layer.close(index);
            }
                ,end:function (index,layero) {
                //var specinfo=window[layero.find('iframe')[0]['name']].specinfo;
                //alert(specinfo);
            }
        });
        // layer.full(index2);
    };



    var specInfo="";
    var provinceId=0;
    var cityId=0;
    var areaId=0;
    var addressId=0;
    var logName="";
    var phone="";
    var detailAddr="";
    var remark="";

    var logType=1;
    var logGoodsInfo="";
    $("#logName").blur(function () {
        logName=$("#logName").val();
    });
    $("#phone").blur(function () {
        phone=$("#phone").val();
    });
    $("#remark").blur(function () {
        remark=$("#remark").val();
    });
    $("#detailAddr").blur(function () {
        detailAddr=$("#detailAddr").val();
    });

    var table;
    var form1;
    var state=1;

    $(document).on("click","#goodsinfo input",function(){
// alert(1);
    });

    function sure(obj){
        var submitter=$("#submitter").val();
        var orderRemark=$("#remark").val();
        // data: {
        //
        //     pkid :$("#form_portPkid").val(),
        //         port: $("#form_port").val(),
        //         portName: $("#form_portName").val(),
        // },
        var url='/goods?url=Order%2FadminOrderCreate' +
            '&cityId='+cityId+
            '&provinceId='+provinceId+
            '&areaId='+areaId+
            '&logName='+logName+
            '&phone='+phone+
            '&detailAddr='+detailAddr+
            '&logType='+logType+
            '&logGoodsInfo='+logGoodsInfo+
            '&sInfo='+sInfo+
            '&submitter='+submitter+
            '&orderRemark='+orderRemark;

        var allData = {
            "cityId":cityId,
            "provinceId":provinceId,
            "areaId":areaId,
            "logName":logName,
            "phone":phone,
            "detailAddr":detailAddr,
            "logType":logType,
            "logGoodsInfo":logGoodsInfo,
            "sInfo":sInfo,
            "submitter":submitter,
            "orderRemark":orderRemark
        };
        $.ajax({
            url: "/goods1?url=Order%2FadminOrderCreate",
            type: "POST",
            data:JSON.stringify(allData),
            async:false,
            dataType: 'json',
            contentType: 'application/json',
            success: function(result) {
                if(result.code=="000000"){
                    parent.alert(result.errorDetail);
                    layer.close(); //关闭弹层
                }else {
                    parent.alert(result.errorDetail);
                    layer.close(); //关闭弹层
                }
            }
        });
        // var htmlobj=$.ajax({
        //     url:url,
        //     type: 'post',
        //     async:false,
        //     dataType: 'json',
        //     contentType: 'application/json',
        // });
        // var info=JSON.stringify(htmlobj);
        // if(htmlobj.responseJSON.code=="000000"){
        //     parent.alert(htmlobj.responseJSON.errorDetail);
        //     layer.close(index); //关闭弹层
        //     // $.toast(htmlobj.responseJSON.errorDetail,1000, function() {
        //     //     layer.close(index); //关闭弹层
        //     //     //window.location.href="/wap/openUserCenter";
        //     // });
        //
        // }else {
        //     parent.alert(htmlobj.responseJSON.errorDetail);
        //     layer.close(index); //关闭弹层
        // }
    };


    $(function () {

        $("#goodsinfo").html($.trim(parent.loggoodsinfo));
        logType=$.trim($("#logType").val());
        $('input:checkbox[name="goodsinfo"]:checked').each(function(){
            logGoodsInfo +=$(this).val()+",";
        });
        provinceId=parseInt($.trim(parent.provinceId));
        cityId=parseInt($.trim(parent.cityId));
        areaId=parseInt($.trim(parent.areaId));
        addressId=parseInt($.trim(parent.addressId));
        logName=$("#logName").val();
        phone=$("#phone").val();
        detailAddr=$("#detailAddr").val();
        remark=$.trim(parent.remark);
        layui.use('table', function(){
            table = layui.table,form = layui.form;form1=form;
            // //监听表格复选框选择
            // table.on('checkbox(demo)', function(obj){
            //     console.log(obj)
            // });
            //
            // form.on('switch(stateS)', function (data) {
            //     //开关是否开启，true或者false
            //     var checked = data.elem.checked;
            //     if (checked) {
            //         $("#state").val(1);
            //     }
            //     else {
            //         $("#state").val(0);
            //     }
            // });
            form.on('select(logType)', function (data) {
                logType=data.value;
            });
            form.on('checkbox(goodsinfo)', function(obj){
                logGoodsInfo="";
                $('input:checkbox[name="goodsinfo"]:checked').each(function(){
                    logGoodsInfo +=$(this).val()+",";
                });
            });
            form.on('select(quiz0)', function (data) {
                var option2 = $("<option>").val(0).text("选择市");
                $("#quiz1").html(option2);
                var option3 = $("<option>").val(0).text("选择区");
                $("#quiz2").html(option3);
                loadfy(data.value+"", '1');
                provinceId=data.value;
                //alert(data.value)
            });
            form.on('select(quiz1)', function (data) {
                loadfy(data.value+"", '2');
                cityId=data.value;
                //alert(data.value)
            });
            form.on('select(quiz2)', function (data) {
                areaId=data.value;
                //alert(data.value)
            });
            loadfy(0,'0');
            if(cityId!=0&&state==1){
                loadfy(provinceId+"",'1');
            }
            if(areaId!=0&&state==1){
                loadfy(cityId+"",'2');
            }
        });
    });

    function loadfy(pid,m) {
        $.ajax({
            type: "POST",
            url: "/goodsjson",
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(GetJsonDataS11(pid,m)),
            dataType: "json",
            async:false,
            success: function (data) {
                if (data.code == "000000") {
                    state=0;
                    var option1;
                    if(m=="0"){
                        option1 = $("<option>").val(0).text("选择省");
                    }
                    if(m=="1"){
                        option1 = $("<option>").val(0).text("选择市");
                    }
                    if(m=="2"){
                        option1 = $("<option>").val(0).text("选择区");
                    }
                    $("#quiz"+m).html(option1);
                    $.each(data.data, function (i, item) {
                        var option1;option1 = $("<option>").val(item.id).text(item.name);
                        if(m=="0"){
                            //alert(provinceId+"--"+item.id);
                            if(provinceId==item.id){
                                option1 = $("<option selected='selected'>").val(item.id).text(item.name);
                            } else {
                                option1 = $("<option>").val(item.id).text(item.name);
                            }
                        }
                        if(m=="1"){
                            //alert(item.name);
                            if(cityId==item.id){
                                option1 = $("<option selected='selected'>").val(item.id).text(item.name);
                            } else {
                                option1 = $("<option>").val(item.id).text(item.name);
                            }
                        }
                        if(m=="2"){
                            if(areaId==item.id){
                                option1 = $("<option selected='selected'>").val(item.id).text(item.name);
                            } else {
                                option1 = $("<option>").val(item.id).text(item.name);
                            }
                        }
                        $("#quiz"+m).append(option1);
                    });
                    state=1;
                    form1.render('select');
                }
                else {
                    alert(data.errorDetail);
                }
            },
            error: function (message) {
                alert("提交数据失败！"+message);
            }
        });
    }

    function GetJsonDataS11(pid,level) {
        var json = {
            "url": "area/getArea",
            "parm":{"parentId":pid,"level":level}
        };
        return json;
    }

    // var index=parent.layer.getFrameIndex(window.name);
    //   var body = layer.getChildFrame('body', index); //得到iframe页的body内容
    //   var orderNo = body.find("#orderNo").val();
    $("#orderNo").html(parent.orderNo);
    $("#logName").val(parent.logName);
    $("#phone").val(parent.phone);
    $("#detailAddr").val(parent.detailAddr);
    $("#remark").val(parent.remark);
    // var orderNo="";
    // var logName="";
    // var phone="";
    // var detailAddr="";

</script>
</body>
</html>